<%-- 
    Document   : viewsale
    Created on : Oct 28, 2012, 1:46:40 AM
    Author     : Ahsan
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="ca.trader.beans.java.SaleLookupByIDBean"%>
<%@page import="ca.trader.beans.java.LookupIfSaleFavouritedByAuthenticatedUserBean"%>
<%@ taglib uri="/WEB-INF/tlds/PrintSale.tld" prefix="sale" %>
<!DOCTYPE html>
<html>
    <head>
        <jsp:include page="head.jsp" />
    </head>
    <body>
	<c:choose>
	    <c:when test="${empty param.id}" >
		Missing parameter "id".
	    </c:when>

	    <c:otherwise>
		<jsp:useBean id="sale" class="ca.trader.beans.java.SaleLookupByIDBean" scope="request" />	
		<jsp:setProperty name="sale" property="saleID" param="id"/>
		<c:choose>
		    <c:when test="${!sale.resultsFound}">
			No results found.
		    </c:when>
		    <c:otherwise>

			<jsp:useBean id="ifSaleFavouritedByAuthenticatedUser" class="ca.trader.beans.java.LookupIfSaleFavouritedByAuthenticatedUserBean" scope="request" />	

			<%
						ifSaleFavouritedByAuthenticatedUser.setSession(session);
			%>
			<jsp:setProperty name="ifSaleFavouritedByAuthenticatedUser" property="sale" value="${sale.sale}"/>
			<sale:PrintSale sale="${sale.sale}" favouritedByAuthenticatedUser="${ifSaleFavouritedByAuthenticatedUser.saleFavourited}" />

			<br/>
			<h3>Post a comment</h3>
			<textarea id='commentString' rows="8" cols="50"></textarea>
			<input type="hidden" id="saleID" value="<c:out value="${param.id}" />"><br/>		   
			<input id="post_comment_button" type="submit" value="Post"/>

			<label id="errorTextLabelReg" style="color:red"></label>
		    </c:otherwise>
		</c:choose>
	    </c:otherwise>
	</c:choose>

	<jsp:include page="footer.jsp" />
    </body>
</html>
